package com.teamwork.module03.controller.file;

import com.teamwork.module03.util.FileUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@RestController
@RequestMapping("/img")
public class DownlodController {

    @Value("${upload.basePath}")
    private String basePath;
    @Value("${user.icon}")
    private String usericonpath;

    @Value("${article.imgPath}")
    private String contentImgPath;

    //获取文章封面
    @GetMapping("/arts/{name}")
    public void getCover(@PathVariable("name") String imgname, HttpServletRequest req,HttpServletResponse res) throws IOException {

        FileUtils.downloadFile(basePath,imgname,req,res);

       // System.out.println("执行了下载方法");
    }
    //火球用户头像
    @GetMapping("/user/icon/{name}")
    public void getUserCover(@PathVariable("name") String imgname, HttpServletRequest req,HttpServletResponse res) throws IOException {

        FileUtils.downloadFile(usericonpath,imgname,req,res);

       // System.out.println("执行了下载方法");
    }
    //获取文章内容图片
    @GetMapping("/content/{name}")
    public void getContentImg(@PathVariable("name")String imgname,HttpServletRequest req,HttpServletResponse res){
        FileUtils.downloadFile(contentImgPath,imgname,req,res);

    }

}
